package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.ArrayList;
import java.util.List;

public class CollectionOperator {
    public List<Integer> getListByInterval(int left, int right) {
        List<Integer> list = new ArrayList<>();
        if (left < right) {
            for (int i = left; i <= right; i++) {
                list.add(i);
            }
        } else {
            for (int i = left; i >= right; i--) {
                list.add(i);
            }
        }

        return list;
    }

    public List<Integer> getEvenListByIntervals(int left, int right) {
        List<Integer> list = new ArrayList<>();
        if (left < right) {
            for (int i = left; i <= right; i++) {
                if (i % 2 == 0) {
                    list.add(i);
                }

            }
        } else {
            for (int i = left; i >= right; i--) {
                if (i % 2 == 0) {
                    list.add(i);
                }
            }
        }

        return list;
    }
    public List<Integer> popEvenElments(int[] array) {
        List<Integer> list=new ArrayList<>();
        for (int i:array){
            if (i%2==0){
                list.add(i);
            }
        }

        return list;
    }

    public int popLastElment(int[] array) {
        return array[array.length-1];
    }

    public List<Integer> popCommonElement(int[] firstArray, int[] secondArray) {
        List<Integer> list=new ArrayList<>();
        for (int i:firstArray){
            for (int it:secondArray){
                if (i==it){
                    list.add(i);
                }
            }
        }
        return list;
    }

    public List<Integer> addUncommonElement(Integer[] firstArray, Integer[] secondArray) {
        boolean b=false;

        List<Integer> list=new ArrayList<>();
        for (Integer i:firstArray){
            list.add(i);
        }
        for (int it:secondArray){
            System.out.println(it);
            for (int i:firstArray){
                if (i==it){
                    b=true;
                }
            }
            if (b==false){
                list.add(it);
            }
            b=false;
        }
        return list;
    }
}
